package my.hnb.android.view.karaoke;

import my.hnb.android.dto.MenuItemDTO;
import my.hnb.android.listenner.OnEventListener;
import my.hnb.songnhac.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MenuItemRow extends LinearLayout {
	OnEventListener listener;
	Context mContext;
	LinearLayout llRow;
	public TextView tvText;
	ImageView ivIcon;

	public MenuItemRow(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
		initMenu();
	}

	public MenuItemRow(Context context) {
		super(context);
		mContext = context;
		initMenu();
	}

	private void initMenu() {
		LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = vi.inflate(R.layout.layout_menu_item, null);

		tvText = (TextView) view.findViewById(R.id.tvText);
		ivIcon = (ImageView) view.findViewById(R.id.ivIcon);
		llRow = (LinearLayout) view.findViewById(R.id.llRow);
	}


	public void setValueMenu(String text, int iconId){
		tvText.setText(text);
		ivIcon.setImageResource(iconId);
	}
	
	
	public void populateFrom(MenuItemDTO item) {
		if (item != null) {
			tvText.setText(item.getTextMenu());
			if (item.getIconMenu() != 0) {
				ivIcon.setVisibility(VISIBLE);
			} else {
				ivIcon.setVisibility(INVISIBLE);
			}
			ivIcon.setImageResource(item.getIconMenu());
		}
	}

	public void setBackground(int res) {
		if (llRow != null)
			llRow.setBackgroundResource(res);
	}
}
